package com.example.sangong.config;

import com.example.sangong.interceptor.LoginInterceptor;
import com.example.sangong.interceptor.RequestLogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration

public class WebConfig implements WebMvcConfigurer {
    @Resource
    private RequestLogInterceptor requestLogInterceptor;
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册⾃定义拦截器对象
        registry.addInterceptor(loginInterceptor)
                //设置拦截器拦截的请求路径（ /** 表示拦截所有请求）
                .addPathPatterns("/**").excludePathPatterns("/user/login");
        registry.addInterceptor(requestLogInterceptor)
                //设置拦截器拦截的请求路径（ /** 表示拦截所有请求）
                .addPathPatterns("/**");
        ;
    }
}
